package com.bean;

import com.annotation.Nigger;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author Cc
 * 2024-03-26
 */
public class WorkProxy implements InvocationHandler {
    public static Work createProxy(People people) {
        Work work = (Work) Proxy.newProxyInstance(
                WorkProxy.class.getClassLoader(),
                new Class[]{Work.class},
                (proxy, method, args) -> {
                    if (people.getClass().isAnnotationPresent(Nigger.class)) {
                        System.out.println("鞭子声：哒哒哒......");
                        if ("slave".equals(people.getClass().getAnnotation(Nigger.class).value())){
                            System.out.println("Dead Nigger");
                        }
                    }
                    return method.invoke(people, args);
                }
        );
        return work;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        return null;
    }
}
